Test Series - Data Structure

Test Number 31/115

Q: Reversing a word using stack can be used to find if the given word is a palindrome or not.
A. True
B. False
C. 
D. 
Solution: This application of stack can also be used to find if the given word is a palindrome because, if the reversed is same as that of the original word, the given word is a palindrome.
Q: Which is the most appropriate data structure for reversing a word?
A. queue
B. stack
C. tree
D. graph
Solution: Stack is the most appropriate data structure for reversing a word because stack follows LIFO principle.
Q: Operations required for reversing a word or a string using stack are push() and pop().
A. True
B. False
C. 
D. 
Solution: Push operation inserts a character into the stack and pop operation pops the top of the stack.
Q: What is the time complexity of reversing a word using stack algorithm?
A. O (N log N)
B. O (N2)
C. O (N)
D. O (M log N)
Solution: The time complexity of reversing a stack is mathematically found to be O (N) where N is the input.
Q: What will be the word obtained if the word “abbcabb” is reversed using a stack?
A. bbabbca
B. abbcabb
C. bbacbba
D. bbacabb
Solution: The string “abbcabb” is pushed on to the stack. If the characters are popped one by one, the word obtained will be bbacbba.
Q: How many stacks are required for reversing a word algorithm?
A. one
B. two
C. three
D. four
Solution: Only 1 stack is required for reversing a word using stack. In that stack, push and pop operations are carried out.
Q:  What will be output if the following sequence of operations are executed?

Push(a,s);
Push(b,s);
Pop(b);
Push(c,s);
A. abc
B. b
C. ac
D. acb
Solution: The element ‘b’ is popped out of the stack. Hence the output of the following sequence of operations will be ‘b’.
Q: What are the set of functions that are to be executed to get the following output?
cat
A. push(c, s); push(a, s); push(t, s); pop(s); pop(s); pop(s);
B. push(c,s); pop(s); push(a,s); pop(s);push(t,s);pop(s);
C. pop(c ); pop(a); pop(t);
D. push(c,s); push(a,s); pop(t);
Solution: During push operation, the characters ‘c’, ’a’, ’t’ are inserted into the stack and popped immediately after push.

You Have Score    /8